//
//  UIButton+UIButton_Extension.m
//  weibo_swift
//
//  Created by 紫荆秋雪 on 16/12/5.
//  Copyright © 2016年 紫荆秋雪. All rights reserved.
//

#import "UIButton+UIButton_Extension.h"

@implementation UIButton (UIButton_Extension)
/**
 创建按钮
 
 @param title 按钮文字
 @param fontSize 文字大小
 @param normalName 正常情况下的图片名称
 @param highlightName 高亮状态下的图片名称
 @return 自定义按钮
 */
+ (UIButton *)buttonTitle:(NSString *) title fontSize:(CGFloat) fontSize imageNormalName:(NSString *) normalName imageHighlightName:(NSString *) highlightName {
    
    return [self buttonTitle:title titleColor:nil fontSize:fontSize imageNormalName:normalName imageHighlightName:highlightName backGroundImageName:nil backGroundColor:nil];
}


+ (UIButton *)buttonTitle:(NSString *)title titleColor:(UIColor *) titleColor fontSize:(CGFloat)fontSize imageNormalName:(NSString *)normalName imageHighlightName:(NSString *)highlightName backGroundImageName:(NSString *) bgImage backGroundColor:(UIColor *) bgColor {
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:title forState:UIControlStateNormal];
    //设置文字颜色
    UIColor *tc;
    if (titleColor) {
        tc = titleColor;
    } else {
        tc = [UIColor darkGrayColor];
    }
    [btn setTitleColor:tc forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    btn.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    [btn setImage:[UIImage imageNamed:normalName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:highlightName] forState:UIControlStateHighlighted];
    //背景图片
    if (bgImage) {
        [btn setBackgroundImage:[UIImage imageNamed:bgImage] forState:UIControlStateNormal];
    }
    
    //背景颜色
    if (bgColor) {
        [btn setBackgroundColor:bgColor];
    } else {
        [btn setBackgroundColor:[UIColor clearColor]];
    }
    // 自适应
    [btn sizeToFit];
    return btn;
}


@end
